<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--文件上传设置-->
      <div class="common-form">{{$t('setting.file_upload_settings')}}</div>
      <el-form-item :label="$t('setting.max_image_upload')">
        <el-input v-model="form.maxImage" class="max-w460">
          <template #append>M</template>
        </el-input>
        <div class="tips">{{$t('setting.config_change_note')}}</div>
      </el-form-item>
      <el-form-item :label="$t('setting.max_video_upload')">
        <el-input v-model="form.maxVideo" class="max-w460">
          <template #append>M</template>
        </el-input>
        <div class="tips">{{$t('setting.config_change_note')}}</div>
      </el-form-item>
      <el-form-item :label="$t('setting.delete_with_storage')">
        <div>
          <el-radio v-model="form.isDelete" :label="1">{{$t('setting.turn_on')}}</el-radio>
          <el-radio v-model="form.isDelete" :label="0">{{$t('setting.turn_off')}}</el-radio>
        </div>
      </el-form-item>
      <el-form-item :label="$t('setting.default_upload_mode')">
        <div>
          <el-radio v-model="form.current" label="Local" @change="getRadio"
            >{{$t('setting.local_storage')}}</el-radio
          >
          <el-radio v-model="form.current" label="QiNiu" @change="getRadio"
            >{{$t('setting.qiniu_storage')}}</el-radio
          >
          <el-radio v-model="form.current" label="AliYun" @change="getRadio"
            >{{$t('setting.aliyun_oss')}}</el-radio
          >
          <el-radio v-model="form.current" label="QCloud" @change="getRadio"
            >{{$t('setting.tencent_cos')}}</el-radio
          >
          <el-radio v-model="form.current" label="HwCloud" @change="getRadio"
            >{{$t('setting.huawei_obs')}}</el-radio
          >
        </div>
      </el-form-item>
      <!--七牛云存储-->
      <div v-if="form.current == 'QiNiu'">
        <el-form-item :label="$t('setting.bucket_name')"
          ><el-input v-model="form.qiNiu.bucket" class="max-w460"></el-input
        ></el-form-item>
        <el-form-item label="ACCESS_KEY AK"
          ><el-input v-model="form.qiNiu.accessKey" class="max-w460"></el-input
        ></el-form-item>
        <el-form-item label="SECRET_KEY SK"
          ><el-input v-model="form.qiNiu.secretKey" class="max-w460"></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.storage_domain')">
          <el-input v-model="form.qiNiu.domain" class="max-w460"></el-input>
          <div class="tips"> {{$t('setting.storage_domain_tip')}} 

</div>
        </el-form-item>
      </div>
      <!--阿里云OSS-->
      <div v-if="form.current == 'AliYun'">
        <el-form-item :label="$t('setting.bucket_name')"
          ><el-input v-model="form.aliYun.bucket" class="max-w460"></el-input
        ></el-form-item>
        <el-form-item label="AccessKeyId"
          ><el-input
            v-model="form.aliYun.accessKeyId"
            class="max-w460"
          ></el-input
        ></el-form-item>
        <el-form-item label="AccessKeySecret"
          ><el-input
            v-model="form.aliYun.accessKeySecret"
            class="max-w460"
          ></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.public_endpoint')">
          <el-input v-model="form.aliYun.endpoint" class="max-w460"></el-input>
          <div class="tips">{{$t('setting.endpoint_example')}}</div>
        </el-form-item>
        <el-form-item :label="$t('setting.storage_domain')">
          <el-input v-model="form.aliYun.domain" class="max-w460"></el-input>
          <div class="tips"> {{$t('setting.storage_domain_tip')}} 

</div>
        </el-form-item>
      </div>
      <!--腾讯云COS-->
      <div v-if="form.current == 'QCloud'">
        <el-form-item :label="$t('setting.bucket_name')"
          ><el-input v-model="form.qcloud.bucket"></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.region')">
          <el-input v-model="form.qcloud.region"></el-input>
          <div class="tips"> {{$t('setting.region_tip')}} 

</div>
        </el-form-item>
        <el-form-item label="SecretId"
          ><el-input v-model="form.qcloud.secretId"></el-input
        ></el-form-item>
        <el-form-item label="SecretKey"
          ><el-input v-model="form.qcloud.secretKey"></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.storage_domain')">
          <el-input v-model="form.qcloud.domain"></el-input>
          <div class="tips"> {{$t('setting.storage_domain_tip')}} 

</div>
        </el-form-item>
      </div>
      <!--华为云OBS-->
      <div v-if="form.current == 'HwCloud'">
        <el-form-item :label="$t('setting.storage_endpoint')"
          ><el-input v-model="form.hwCloud.endPoint" class="max-w460"></el-input
        ></el-form-item>
        <el-form-item label="AccessKeyId"
          ><el-input
            v-model="form.hwCloud.accessKeyId"
            class="max-w460"
          ></el-input
        ></el-form-item>
        <el-form-item label="AccessKeySecret"
          ><el-input
            v-model="form.hwCloud.accessKeySecret"
            class="max-w460"
          ></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.bucket_name2')"
          ><el-input
            v-model="form.hwCloud.bucketName"
            class="max-w460"
          ></el-input
        ></el-form-item>
        <el-form-item :label="$t('setting.access_domain')">
          <el-input v-model="form.hwCloud.domain" class="max-w460"></el-input>
          <div class="tips"> {{$t('setting.storage_domain_tip')}} 

</div>
        </el-form-item>
      </div>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >{{$t('setting.submit_button')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from "@/api/setting.js";
export default {
  data() {
    return {
      /*切换菜单*/
      // activeIndex: '1',
      /*form表单数据*/
      form: {
        current: "Local",
        maxImage: "",
        maxVideo: "",
        qiNiu: {},
        aliYun: {},
        qcloud: {},
        hwCloud: {},
        isDelete: 0
      },
      loading: false
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      let self = this;
      SettingApi.storageDetail({}, true).then(res => {
        self.form = res.data;
      }).catch(error => {});
    },
    //提交表单
    onSubmit() {
      let self = this;
      self.loading = true;
      let params = this.form;
      SettingApi.editStorage(params, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("setting.upload_setting_success"),
          type: "success"
        });
      }).catch(error => {
        self.loading = false;
      });
    },
    //监听单选按钮
    getRadio(val) {}
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

